package com.qs.springboot.amqp.topic;

import com.qs.springboot.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者：指定exchange的类型为topic（允许使用* #通配指定routingKey）
 */
public class Send {

    private static final String exchange_name = "topic_exchange_test";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        //声明exchange，指定类型为topic
        channel.exchangeDeclare(exchange_name, "topic");

        //发送消息
        String message = "新增商品：id=1001";
        channel.basicPublish(exchange_name, "item.insert", null, message.getBytes());
        System.out.println("【商品服务】send：" + message);

        String message2 = "删除商品：id=1001";
        channel.basicPublish(exchange_name, "item.delete", null, message2.getBytes());
        System.out.println("【商品服务】send：" + message2);

        channel.close();
        connection.close();
    }
}
